import { Component, OnDestroy } from '@angular/core';

import { Util } from '../../../utils/util';

import { WordDetailProductService } from './word.product.service';

import { ToastyService } from '../../../modules/ng2-toasty';

import { ProductBase } from '../../product/product.base';

@Component({
  selector: 'word-product',
  templateUrl: './word.product.html',
  styles: [`
  `],
  providers: [WordDetailProductService]
})


export class WordDetailProductComponent extends ProductBase {

  // 参数
  param: any = {
    catName:'',
    categoryId: '',
    q: '',
    start: 0,
    rows: 10,
    sort: 'sellMoney',
    sortType: 'desc'
  };

  wordInfo: any;

  constructor(public util: Util, public service: WordDetailProductService,public toastyService:ToastyService) {
    super(service,util,toastyService);

    this.wordInfo = this.util.sessionStore().get('wordDetail');

    this.param.categoryId = this.wordInfo.categoryId;

    this.param.catName = this.wordInfo.categoryName;

    this.param.q = this.wordInfo.words;

    this.getHttp(this.param);
  }

  ngOnDestroy() {

    if (this.busy) {
      this.busy.unsubscribe();
    }

    if(this.busy2){
      this.busy2.unsubscribe();
    }
  }

  
  getHttp(param){

    let res ={"code":0,"msg":"成功","data":{"value":[{"date":"2018-05-26 00:00:00","numberId":"566741234264","title":"2018新款 Apple/苹果 9.7英寸iPad wifi版 智能平板电脑A10芯片","picUrl":"//img.alicdn.com/imgextra/i2/2616970884/TB1xc_bhlyWBuNkSmFPXXXguVXa_!!0-item_pic.jpg","loc":"江苏南京","propertyValue":"处理器品牌:Apple/苹果,分辨率:2048x1536,品牌:Apple/苹果,套餐类型:官方标配+玫瑰金保护套 官方标配+藏青色保护套 官方标配+钢化膜 官方标配,型号:Ipad,存储容量:32GB 128GB,屏幕尺寸:9.7英寸,热门功能:重力感应 光线感应,后置摄像头像素:800万,网络类型:WLAN,售后服务:全国联保,颜色分类:深空灰色 金色 银色,操作系统:iOS,内存容量:2GB,保修期:12个月,触摸屏类型:电容式","brandName":"apple/苹果","price":2328.0,"monthPrice":2411.38,"quantity":0,"monthSellAmount":16673,"monthSellMoney":4.0204944E7,"sellAmount":648,"sellMoney":1508544.0,"category":"50019780","catName":"数码/手机/家电--平板电脑/MID","uid":"2616970884","shopName":"苏宁易购官方旗舰店","shopType":"商城","publishTime":null},{"date":"2018-05-26 00:00:00","numberId":"547137374482","title":"2017款Apple/苹果 iPad 9.7英寸平板电脑32G/128G wifi版原封便携","picUrl":"//img.alicdn.com/imgextra/i1/2616970884/TB1y9jZpqmWBuNjy1XaXXXCbXXa_!!0-item_pic.jpg","loc":"江苏南京","propertyValue":"处理器品牌:Apple/苹果,分辨率:2048×1536,品牌:Apple/苹果,套餐类型:官方标配+玫瑰金保护套 官方标配+藏青色保护套 官方标配+钢化膜 官方标配,型号:Ipad,存储容量:32GB 128GB,屏幕尺寸:9.7英寸,处理器型号信息:A9 芯片嵌入式 M9 协处理器,热门功能:重力感应 光线感应,后置摄像头像素:800万,厂商:苹果,生产企业:苹果公司,网络类型:WLAN,售后服务:全国联保,颜色分类:金色 银色,操作系统:iOS,内存容量:2GB,接口类型:音频接口 电脑锁,保修期:12个月,触摸屏类型:电容式","brandName":"apple/苹果","price":2168.0,"monthPrice":2112.36,"quantity":0,"monthSellAmount":7506,"monthSellMoney":1.5855398E7,"sellAmount":436,"sellMoney":945248.0,"category":"50019780","catName":"数码/手机/家电--平板电脑/MID","uid":"2616970884","shopName":"苏宁易购官方旗舰店","shopType":"商城","publishTime":null},{"date":"2018-05-26 00:00:00","numberId":"522542463386","title":"Apple/苹果 iPad mini4 7.9英寸平板电脑128GWiFi版迷你平板电脑","picUrl":"//img.alicdn.com/imgextra/i1/2616970884/TB1HxsHpCtYBeNjSspaXXaOOFXa_!!0-item_pic.jpg","loc":"山东济南","propertyValue":"处理器品牌:Apple/苹果,分辨率:2048 x 1536 分辨率，326 ppi,品牌:Apple/苹果,CPU主频:不详,套餐类型:官方标配,型号:iPad mini 4,存储容量:128GB,屏幕尺寸:7.9 英寸 (对角线) LED 背光 Multi-Touch 显示屏,处理器型号信息:不详,处理器构架:不详,后置摄像头像素:800 万像素 iSight 摄像头,生产企业:苹果公司,网络类型:WLAN,售后服务:全国联保,电信设备进网许可证编号:不详,颜色分类:金色 深空灰色 银色,内存容量:不详,保修期:12个月","brandName":"apple/苹果","price":2788.0,"monthPrice":2661.49,"quantity":0,"monthSellAmount":4861,"monthSellMoney":1.2937511E7,"sellAmount":265,"sellMoney":738820.0,"category":"50019780","catName":"数码/手机/家电--平板电脑/MID","uid":"2616970884","shopName":"苏宁易购官方旗舰店","shopType":"商城","publishTime":null},{"date":"2018-05-26 00:00:00","numberId":"566534680696","title":"[12期分期]Apple/苹果 iPad 2018款 9.7英寸wifi新款平板电脑128G","picUrl":"//img.alicdn.com/imgextra/i3/1669409267/TB2owITrqmWBuNjy1XaXXXCbXXa_!!1669409267.jpg","loc":"上海","propertyValue":"存储类型:闪存,型号:iPad 2018款,存储容量:32GB 128GB,屏幕尺寸:9.7英寸,热门功能:重力感应 原笔迹手写 罗盘功能 蓝牙 智能重力感应,厂商:苹果,生产企业:苹果公司,网络类型:WLAN,上市时间:2018-03-28,售后服务:全国联保,核心数:四核心,颜色分类:金色 银色 深空灰色,内存容量:2GB,接口类型:lighting,处理器品牌:Apple/苹果,分辨率:2048x1536,品牌:Apple/苹果,CPU主频:不详,套餐类型:官方标配 套餐一 套餐二 套餐三 套餐四 套餐五,是否PC平板二合一:否,处理器型号信息:A10,处理器构架:苹果专属架构,后置摄像头像素:800万,电信设备进网许可证编号:无,操作系统:iOS,保修期:12个月,触摸屏类型:电容屏","brandName":"apple/苹果","price":2338.0,"monthPrice":2356.35,"quantity":0,"monthSellAmount":7544,"monthSellMoney":1.7776312E7,"sellAmount":142,"sellMoney":331996.0,"category":"50019780","catName":"数码/手机/家电--平板电脑/MID","uid":"1669409267","shopName":"卓辰数码旗舰店","shopType":"商城","publishTime":null},{"date":"2018-05-26 00:00:00","numberId":"567144656257","title":"Apple/苹果 iPad 2018款 苹果平板电脑9.7英寸ipad 新款ipad2018","picUrl":"//img.alicdn.com/imgextra/i4/97045700/TB2LkhVph1YBuNjy1zcXXbNcXXa_!!97045700.jpg","loc":"广东深圳","propertyValue":"处理器品牌:Apple/苹果,分辨率:2048x1536,品牌:Apple/苹果,CPU主频:不详,存储类型:闪存,套餐类型:官方标配，套餐一，套餐二，套餐三，套餐四，套餐五,是否PC平板二合一:否,型号:iPad 2018款,存储容量:32GB，128GB,屏幕尺寸:9.7英寸,热门功能:重力感应，原笔迹手写，罗盘功能，光线感应，蓝牙，GPS，智能重力感应，方向感应器,成色:全新,网络类型:WIFI，4G,上市时间:2018-03-28,版本类型:港澳台,售后服务:店铺三包,核心数:四核心,是否支持蓝牙:支持,操作系统:iOS,内存容量:不详,接口类型:Lighting,触摸屏类型:电容屏,摄像头类型:双摄像头","brandName":"apple/苹果","price":1838.0,"monthPrice":1891.84,"quantity":0,"monthSellAmount":3467,"monthSellMoney":6558996.0,"sellAmount":161,"sellMoney":295918.0,"category":"50019780","catName":"数码/手机/家电--平板电脑/MID","uid":"97045700","shopName":"苹安数码科技","shopType":"全球购","publishTime":null},{"date":"2018-05-26 00:00:00","numberId":"566798155649","title":"Apple/苹果 iPad 2018款 9.7英寸ipad苹果平板电脑 ipad2018新款","picUrl":"//img.alicdn.com/imgextra/i1/126195000/TB2K2mcsXGWBuNjy0FbXXb4sXXa_!!126195000.jpg","loc":"广东深圳","propertyValue":"处理器品牌:Apple/苹果,分辨率:2048x1536,品牌:Apple/苹果,CPU主频:不详,存储类型:闪存,套餐类型:官方标配，套餐一，套餐二，套餐三，套餐四，套餐五,是否PC平板二合一:否,型号:iPad 2018款,存储容量:32GB，128GB,屏幕尺寸:9.7英寸,热门功能:重力感应，原笔迹手写，罗盘功能，光线感应，蓝牙，GPS，智能重力感应，方向感应器,成色:全新,网络类型:WIFI，4G,上市时间:2018-03-28,版本类型:港澳台,核心数:四核心,操作系统:iOS,内存容量:不详,接口类型:Lighting,触摸屏类型:电容屏","brandName":"apple/苹果","price":1828.0,"monthPrice":1907.47,"quantity":0,"monthSellAmount":2552,"monthSellMoney":4867867.54,"sellAmount":104,"sellMoney":190112.0,"category":"50019780","catName":"数码/手机/家电--平板电脑/MID","uid":"126195000","shopName":"拓普数码","shopType":"全球购","publishTime":null},{"date":"2018-05-26 00:00:00","numberId":"528938575932","title":"Huawei/华为 平板 M5 10.8英寸通话全网通手机WIFI二合一电脑安卓","picUrl":"//img.alicdn.com/imgextra/i2/2711014365/TB2GyOxlER1BeNjy0FmXXb0wVXa_!!2711014365.jpg","loc":"广东深圳","propertyValue":"存储类型:闪存,型号:平板 M5 10.8英寸,存储容量:32GB 64GB 128GB,屏幕尺寸:10.8英寸,热门功能:电脑模式、指纹导航、学生模式、护眼模式 重力感应 罗盘功能 光线感应 蓝牙,厂商:华为,生产企业:华为,网络类型:Wi-Fi 全网通通话版,上市时间:2018-4-12,售后服务:全国联保,核心数:八核+微智核i6,颜色分类:香槟金 深空灰,内存容量:128GB 32GB 64GB,接口类型:支持USB Type-C接口,分辨率:2560x1600,品牌:Huawei/华为,CPU主频:4×A73@2.1GHz + 4×A53@1.8GHz,套餐类型:官方标配 套餐一 套餐二 套餐三 套餐四 套餐五,是否PC平板二合一:否,处理器型号信息:海思麒麟960s,处理器构架:Mali G71 MP8,后置摄像头像素:1300万,电信设备进网许可证编号:17-5043-174372,操作系统:Android 8.0,保修期:12个月,像素:2100万,触摸屏类型:电容屏","brandName":"huawei/华为","price":2488.0,"monthPrice":2488.0,"quantity":0,"monthSellAmount":1872,"monthSellMoney":4657536.0,"sellAmount":54,"sellMoney":134352.0,"category":"50019780","catName":"数码/手机/家电--平板电脑/MID","uid":"2711014365","shopName":"华为卓瑞尔专卖店","shopType":"商城","publishTime":null},{"date":"2018-05-26 00:00:00","numberId":"566474172900","title":"Huawei/华为 平板 M5 10.8英寸全网通WiFi安卓4G通话电脑智能手机","picUrl":"//img.alicdn.com/imgextra/i2/3684904051/TB2hM38lXGWBuNjy0FbXXb4sXXa_!!3684904051-0-item_pic.jpg","loc":"上海","propertyValue":"型号:平板 M5 10.8英寸,存储容量:64GB 32GB 128GB,屏幕尺寸:10.8英寸,热门功能:电脑模式、指纹导航、学生模式、护眼模式 重力感应 罗盘功能 光线感应 蓝牙,厂商:华为,生产企业:华为,网络类型:全网通通话版 Wi-Fi,上市时间:2018-4-12,售后服务:全国联保,核心数:八核+微智核i6,颜色分类:香槟金 深空灰,内存容量:128GB 32GB 64GB,接口类型:支持USB Type-C接口,处理器品牌:海思,分辨率:2560x1600,品牌:Huawei/华为,CPU主频:4×A73@2.1GHz + 4×A53@1.8GHz,套餐类型:套餐六 官方标配 套餐一 套餐二 套餐三 套餐四 套餐五,是否PC平板二合一:否,处理器型号信息:海思麒麟960s,处理器构架:Mali G71 MP8,后置摄像头像素:1300万,电信设备进网许可证编号:17-5043-174372,操作系统:Android 8.0,保修期:12个月,像素:2100万,触摸屏类型:电容屏","brandName":"huawei/华为","price":2488.0,"monthPrice":2488.0,"quantity":0,"monthSellAmount":2241,"monthSellMoney":5575608.0,"sellAmount":51,"sellMoney":126888.0,"category":"50019780","catName":"数码/手机/家电--平板电脑/MID","uid":"3684904051","shopName":"枭舜数码专营店","shopType":"商城","publishTime":null},{"date":"2018-05-26 00:00:00","numberId":"566610318179","title":"【新品发售使用预约券减50】Huawei/华为 M5 平板电脑10.8英寸","picUrl":"//img.alicdn.com/imgextra/i2/2838892713/TB2O5pllAKWBuNjy1zjXXcOypXa_!!2838892713-0-item_pic.jpg","loc":"广东深圳","propertyValue":"型号:平板 M5 10.8英寸,存储容量:32GB 64GB 128GB,屏幕尺寸:10.8英寸,热门功能:电脑模式、指纹导航、学生模式、护眼模式 重力感应 罗盘功能 光线感应 蓝牙,厂商:华为,生产企业:东莞长城开发科技有限公司,网络类型:Wi-Fi 全网通通话版,上市时间:2018-4-12,核心数:八核+微智核i6,颜色分类:香槟金 深空灰,内存容量:4GB,接口类型:支持USB Type-C接口,分辨率:2560x1600,品牌:Huawei/华为,CPU主频:4×A73@2.1GHz + 4×A53@1.8GHz,套餐类型:官方标配,是否PC平板二合一:否,处理器型号信息:海思麒麟960s,处理器构架:Mali G71 MP8,后置摄像头像素:1300万,电信设备进网许可证编号:17-5043-174372,操作系统:Android 8.0,保修期:12个月,像素:前置800万+后置1300万,触摸屏类型:电容屏","brandName":"huawei/华为","price":2488.0,"monthPrice":2488.0,"quantity":0,"monthSellAmount":1450,"monthSellMoney":3607600.0,"sellAmount":44,"sellMoney":109472.0,"category":"50019780","catName":"数码/手机/家电--平板电脑/MID","uid":"2838892713","shopName":"华为官方旗舰店","shopType":"商城","publishTime":null},{"date":"2018-05-26 00:00:00","numberId":"566770539949","title":"Huawei/华为 平板 M5 10.8英寸电脑安卓手机10智能全网通话二合一","picUrl":"//img.alicdn.com/imgextra/i1/385131841/TB2yLuTk5CYBuNkHFCcXXcHtVXa_!!385131841.jpg","loc":"广东广州","propertyValue":"型号:平板 M5 10.8英寸,存储容量:64GB 32GB 128GB,屏幕尺寸:10.8英寸,热门功能:电脑模式、指纹导航、学生模式、护眼模式 重力感应 罗盘功能 光线感应 蓝牙,厂商:华为,生产企业:华为技术有限公司,网络类型:全网通通话版 Wi-Fi,上市时间:2018-4-12,售后服务:全国联保,核心数:八核+微智核i6,颜色分类:香槟金 深空灰,内存容量:128GB 32GB 64GB,接口类型:支持USB Type-C接口,处理器品牌:海思,分辨率:2560x1600,品牌:Huawei/华为,CPU主频:4×A73@2.1GHz + 4×A53@1.8GHz,套餐类型:今日前50送键盘双肩包原装四件套等19礼 官方标配,是否PC平板二合一:否,处理器型号信息:海思麒麟960s,处理器构架:Mali G71 MP8,后置摄像头像素:1300万,电信设备进网许可证编号:17-5043-174372,操作系统:Android 8.0,保修期:12个月,像素:2100万,触摸屏类型:电容屏","brandName":"huawei/华为","price":2488.0,"monthPrice":2488.0,"quantity":0,"monthSellAmount":1603,"monthSellMoney":3988264.0,"sellAmount":41,"sellMoney":102008.0,"category":"50019780","catName":"数码/手机/家电--平板电脑/MID","uid":"385131841","shopName":"信沃数码专营店","shopType":"商城","publishTime":null}],"count":923}};

      this.vm.table.products = res.data.value;

      this.vm.table.count = res.data.count;

    
  }

   // 店铺类型切换
  shopType:any='';
  // shopType Change
  shopTypeChange(data) {

    console.log(data);

    if (this.param.shopType === data) {
      return;
    }

    this.param.shopType = data;

    this.getHttp(this.param);

  }

  //
  searchText:any;
  search(){
    if(this.searchText == this.param.q){
      return;
    }
    this.searchText = this.param.q;
    this.getHttp(this.param);
  }



  busy2:any;
  export(){

    let json = Object.assign({},this.param);

    json.rows = 1000;
    json.start = 0;

    // toast
    let toastOptions = {
      title: "",
      msg: "下载中...",
      showClose: true,
      timeout: 6000,
      theme: 'material'
    };
    // Add see all possible types in one shot
    this.toastyService.info(toastOptions);

    this.busy2 = this.service.getProduct(json).subscribe((res: any) => {


      let dim = ['date','numberId','title','picUrl','loc','propertyValue','brandName','price','monthPrice','monthSellAmount','monthSellMoney','sellAmount','sellMoney','category','catName','uid','shopName','shopType'];

      let dimText = ['时间','宝贝Id','宝贝标题','宝贝图片链接','地址','属性','品牌名','成交均价','月成交均价','月销售量','月销售额','销售量','销售额','类目id','类目','店铺id','店铺名','店铺类型'];

      let fileName = this.wordInfo.words+json.catName+json.shopType+"全部宝贝";


      let data = this.util.jsonToArrry(res.data.value, dim,  dimText);

      this.util.export(data, fileName);


    }, (err: any) => {
      this.busy2.unsubscribe();
    });
  }

}
